import getState from "@/api/state";
import { Context } from "@/app-context/main-context";
import Infocard from "@/template/infocard/infocard";
import ZuiEchart from "@/template/zuiEchart/zuiEchart";
import { getRandomMath } from "@/utils/math";
import React, { useContext } from "react";
import { useEffect } from "react";
import { useState } from "react";

const Actmodule6 = () => {
    const [message, setMessage] = useState("暂无数据");
    const { condition } = useContext(Context)
    const [loading, setLoading] = useState(true);
    const [state1, setState1] = useState({
        "dayList": ["2022/01", "2022/02", "2022/03", "2022/04", "2022/05", "2022/06", "2022/07", "2022/08", "2022/09", "2022/10", "2022/11", "2022/12"],
        data: [
            // {
            //     name: "违法人数",
            //     value: getRandomMath(0, 100, 6)
            // },
            // {
            //     name: "维修人数",
            //     value: getRandomMath(0, 100, 6)
            // }
        ]
    })
    const [state2, setState2] = useState({
        "dayList": ["2022/01", "2022/02", "2022/03", "2022/04", "2022/05", "2022/06", "2022/07", "2022/08", "2022/09", "2022/10", "2022/11", "2022/12"],
        data: [
            // {
            //     name: "违法人数",
            //     value: getRandomMath(0, 100, 12)
            // },
            // {
            //     name: "维修人数",
            //     value: getRandomMath(0, 100, 12)
            // }
        ]
    })


    useEffect(() => {
        getState({
            setMessage,
            apiUrl: "/cifgp-core-api/actQuery/trendChart",
            condition: { ...condition, cType: "actDrivingBehavior", dateType: "tYear", dateType: "tYear", statDate: condition.dateType === "tYear" ? condition.statDate : "" },
            state: state1,
            setState: setState1,
            setLoading
        })
        getState({
            setMessage,
            apiUrl: "/cifgp-core-api/actQuery/trendChart",
            condition: { ...condition, cType: "actDrivingBehavior", dateType: "tMonth", dateType: "tMonth", statDate: condition.dateType === "tMonth" ? condition.statDate : "" },
            state: state2,
            setState: setState2,
            setLoading
        })
    }, [condition])


    return (
        <>
            <ZuiEchart
                message={message}
                loading={loading}
                btn={["年", "月"]}
                style={{ width: "70%" }}
                defaultModule="adBar"
                title="驾驶行为统计"
                pieType={"2"}
                data={
                    [
                        state1,
                        state2,
                    ]
                }
            />
        </>
    )
}
export default Actmodule6;